package org.restorator.dao.tx;

import org.restorator.exception.DataStoreException;
import org.restorator.exception.TransactionException;

import java.sql.Connection;
import java.util.concurrent.Callable;

public interface TransactionManager {

    /**
     * Gen connection {@link Connection} and bind it to the current thread.
     *
     * @return {@link Connection}
     * @throws DataStoreException some SQLException or.. happened.
     */
    Connection getCurrentConnection() throws DataStoreException;


    /**
     * Pattern Command, as a {@link Callable}, do unit of work in one transaction
     * @param unit unit of work
     */
    <E> E doInTran(Callable<E> unit) throws TransactionException;

}
